package cn.itcast.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/cookie")
public class CookieController {

    @RequestMapping("/c1")
    public String c1(HttpServletResponse response){
        //获取cookie对象
        response.addCookie(new Cookie("name1","33"));
        response.addCookie(new Cookie("name2","663"));
        return "11";
    }

    @RequestMapping("/c2")
    public String c2(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName()+"---->"+cookie.getValue());
        }

        return "22";
    }
}
